package com.bkitmobile.kesu.android.connectServer;

import java.util.HashMap;
import java.util.List;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;

import com.appenginefan.toolkit.common.ClientSocketSubstitute;
import com.bkitmobile.kesu.android.GUI.R;
import com.google.android.maps.GeoPoint;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Handler;

public final class staticClass {
	public static final String hostURL = "http://bkitkesu.appspot.com/";
	public static final String serviceURL = hostURL+"mobile";
	public static final String socketURL = hostURL+"socket";
	public static HttpClient httpclient;
	public static HttpPost httppost;
	public static boolean isRunning = false;
	public static String user;
	public static Handler mHandler;
	public static boolean isActivity = false;
	public static boolean isChat = false;
	public static boolean isFirst = true;
	public static ClientSocketSubstitute socket;
	public static Handler sendToService;
	public static Handler chatHandler;
	public static List<String> isActived;
	public static void rebuild()
	{
		httpclient = null;
		httppost = null;
		isRunning = false;
		user = null;
		mHandler = null;
		isActivity = false;
		isChat = false;
		isFirst = true;
		socket = null;
		sendToService = null;
		chatHandler = null;
		isActived = null;
	}
	public static Drawable getDrawable(int pos, Context context){
		int []types = {R.drawable.m_personal
				 	 , R.drawable.m_airport
				 	 , R.drawable.m_atm
				 	 , R.drawable.m_bank
				 	 , R.drawable.m_bus
				 	 , R.drawable.m_church
				 	 , R.drawable.m_cinema
				 	 , R.drawable.m_circus
				 	 , R.drawable.m_clothes
				 	 , R.drawable.m_coffee
				 	 , R.drawable.m_company
				 	 , R.drawable.m_computer
				 	 , R.drawable.m_construction
				 	 , R.drawable.m_court
				 	 , R.drawable.m_factory
				 	 , R.drawable.m_hospital
				 	 , R.drawable.m_hotel
				 	 , R.drawable.m_lake
				 	 , R.drawable.m_library
				 	 , R.drawable.m_market
				 	 , R.drawable.m_museum
				 	 , R.drawable.m_pagoda
				 	 , R.drawable.m_palace
				 	 , R.drawable.m_park
				 	 , R.drawable.m_resort
				 	 , R.drawable.m_restaurant
				 	 , R.drawable.m_school
				 	 , R.drawable.m_stadium
				 	 , R.drawable.m_toilets
				 	 , R.drawable.m_train
				 	 , R.drawable.m_university
				 	 , R.drawable.m_zoo		
					};
		if(pos >= types.length || pos <0)
			return ((Activity)context).getResources().getDrawable(R.drawable.m_unknow);
		return ((Activity)context).getResources().getDrawable(types[pos]); 
	}
	public static Drawable getDrawable(String type,Context context)
	{
		Drawable drawable = ((Activity)context).getResources().getDrawable(R.drawable.m_unknow);;
		String []types = ((Activity)context).getResources().getStringArray(R.array.map_items);
		if (type.equals("friend")) 
		{
			drawable = ((Activity)context).getResources().getDrawable(R.drawable.friend);
			drawable.setBounds(-drawable.getIntrinsicWidth()/2, -drawable.getIntrinsicHeight()/2, drawable.getIntrinsicWidth()/2, drawable.getIntrinsicHeight()/2);
			return drawable;
		}
		for(int i = 0; i< types.length; i++){
			if(type.equals(types[i])){
				drawable = getDrawable(i, context);
				drawable.setBounds(-drawable.getIntrinsicWidth()/2, -drawable.getIntrinsicHeight(), drawable.getIntrinsicWidth()/2, 0);
				break;
			}
		}
		return drawable;
	}
	public static GeoPoint getPoint(double lat, double lng)
	{
		return(new GeoPoint((int)(lat*1000000.0), (int)(lng*1000000.0)));
	}
}